package com.itheima.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;


import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

public class OSSUtils {
    // Endpoint以杭州为例，其它Region请按实际情况填写。
    private static String endpoint = "http://oss-cn-shanghai.aliyuncs.com";
    // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维，请登录 https://ram.console.aliyun.com 创建RAM账号。
    private static String accessKeyId = "LTAI4GEcYeEYr4e9aL5AWgq5";
    private static String accessKeySecret = "7JSDeEiz5TckbanWRhP7PLEpSH8o8m";
    private static String bucketName ="health-118-sun";

    public static String upload(InputStream inputStream,String objectName) throws IOException {

// 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        ossClient.putObject(bucketName, objectName,inputStream);

// 关闭OSSClient。
        ossClient.shutdown();
        return objectName;
    }
    public static boolean delete(String path){
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        ossClient.deleteObject(bucketName,path);
        ossClient.shutdown();
        return true;
    }
}
